﻿using DTO;
using BLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HDT.GUI
{
    public partial class FrmThemLoaiMH : Form
    {
        public delegate void MyDelegate();
        public MyDelegate refreshForm;

        public FrmThemLoaiMH()
        {
            InitializeComponent();
        }

        private void btnQuayLai_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtLoaiMH_TextChanged(object sender, EventArgs e)
        {
            btnThemLoaiMH.Enabled = !"".Equals(txtLoaiMH.Text.Trim());
        }

        private void btnThemLoaiMH_Click(object sender, EventArgs e)
        {
            try
            {
                LoaiMatHangDTO loai = new LoaiMatHangDTO();
                loai.TenLoaiMatHang = txtLoaiMH.Text.Trim();
                new LoaiMatHangBLL().Insert(loai);
                MessageBox.Show("Thêm loại thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Dispose();
                refreshForm();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "LỖI", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
